package net.hn.hnms.biz.indicator.util;

import net.hn.hnms.biz.indicator.entity.IndicatorBaseKeyDTO;
import net.hn.hnms.biz.indicator.link.DictService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.system.api.domain.SysDictData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 智呈物联 nzw
 * @date 2022/11/10
 */
@Service
public class IndicatorBaseUtil {
    private static DictService dictService;

    @Autowired
    public void setDictService(DictService dictService) {
        this.dictService = dictService;
    }

    public static List<IndicatorBaseKeyDTO> listByType(String type){
        R<List<SysDictData>> r = dictService.dictType(type);
        List<SysDictData> sysDictDataList = r.getData();

        if (sysDictDataList==null){
            return null;
        }
        List<IndicatorBaseKeyDTO> list = new ArrayList<>();
        for (SysDictData sysDictData : sysDictDataList){
            IndicatorBaseKeyDTO indicatorBaseKeyDTO = convert(sysDictData);
            list.add(indicatorBaseKeyDTO);
        }
        return list;
    }

    public static IndicatorBaseKeyDTO convert(SysDictData dto){
        IndicatorBaseKeyDTO re=new IndicatorBaseKeyDTO();
        re.setName(dto.getDictLabel());
        re.setValue(dto.getDictValue());
        return re;
    }
}
